package cn.kai.ums.controller;

import cn.kai.ums.mapper.UmsClassCourseMapper;
import cn.kai.ums.model.UmsClassCourse;
import cn.kai.ums.model.UmsPublicCourse;
import cn.kai.ums.service.UmsClassCourseService;
import cn.kai.ums.tools.JsonData;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.swing.*;
import java.util.List;

@RestController
@RequestMapping("ums/v1/classcourse")
@Api(tags = "必修课控制类")
public class ClassCourseController {

    @Autowired
    private UmsClassCourseService classCourseService;

    @Autowired
    private UmsClassCourseMapper classCourseMapper;



    @ApiOperation("获取学生个人必须课的信息")
    @GetMapping("/getStudentCourse")
    public JsonData getStudentCourse(@RequestParam String stuid){
         List<UmsClassCourse> classCourseList = classCourseService.getStudentCourse(stuid);
        return JsonData.buildSuccess(classCourseList);
    }

    @ApiOperation("获取老师个人必修课的信息")
    @GetMapping("/teachercourse")
    public JsonData teachercourse(@RequestParam String teaid){
        List<UmsClassCourse> classCourseList = classCourseService.teachercourse(teaid);
        return JsonData.buildSuccess(classCourseList);

    }

    @ApiOperation("根据课程编号和课程名称模糊查询")
    @GetMapping
    public  JsonData getClassCourseList(@RequestParam(defaultValue = "1",required = false) Integer pageNum
            ,@RequestParam(defaultValue = "5",required = false) Integer pageSize
            ,@RequestParam(defaultValue = "",value = "likeclasscourse",required = false) String likeclasscourse){

        Page<UmsClassCourse> umsClassCoursePage = classCourseMapper.selectPage(new Page<>(pageNum,pageSize)
                , Wrappers.<UmsClassCourse>lambdaQuery()
                        .like(UmsClassCourse::getClassCourseNo,likeclasscourse)
                        .or()
                        .like(UmsClassCourse::getClassCourseName,likeclasscourse));
        return JsonData.buildSuccess(umsClassCoursePage);
    }

    @PostMapping
    public JsonData saveClassCourse(@RequestBody UmsClassCourse umsClassCourse){
        return JsonData.buildSuccess(classCourseService.save(umsClassCourse));
    }

    @PutMapping
    public JsonData updateClassCourse(@RequestBody UmsClassCourse umsClassCourse){
        return JsonData.buildSuccess(classCourseService.updateById(umsClassCourse));
    }

    @DeleteMapping
    public JsonData delClassCourse(@RequestParam Integer ccid){
        return JsonData.buildSuccess(classCourseService.removeById(ccid));
    }

    @PostMapping("/delBatchClassCourse")
    public JsonData delBatchClassCourse(@RequestBody List<Integer> ccids){
        return JsonData.buildSuccess(classCourseService.removeByIds(ccids));
    }
}
